package com.xmzs.midjourney.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;

import com.xmzs.common.web.core.BaseController;
import com.xmzs.common.mybatis.core.page.PageQuery;
import com.xmzs.common.core.domain.R;
import com.xmzs.common.core.validate.AddGroup;
import com.xmzs.common.core.validate.EditGroup;
import com.xmzs.common.log.enums.BusinessType;

import com.xmzs.midjourney.domain.vo.MjServerVo;
import com.xmzs.midjourney.domain.bo.MjServerBo;
import com.xmzs.midjourney.service.IMjServerService;
import com.xmzs.common.mybatis.core.page.TableDataInfo;

/**
 * MJ服务器信息配置
 *
 * @author lixg
 * @date 2023-08-09
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/midjourney/mjserver")
public class MjServerController extends BaseController {

    private final IMjServerService mjServerService;

    /**
     * 查询MJ服务器信息配置列表
     */
    @SaCheckPermission("midjourney:mjserver:list")
    @GetMapping("/list")
    public TableDataInfo<MjServerVo> list(MjServerBo bo, PageQuery pageQuery) {
        return mjServerService.queryPageList(bo, pageQuery);
    }


    /**
     * 获取MJ服务器信息配置详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("ruoyi-midjourney:mjserver:query")
    @GetMapping("/{id}")
    public R<MjServerVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(mjServerService.queryById(id));
    }

    /**
     * 新增MJ服务器信息配置
     */
    @SaCheckPermission("ruoyi-midjourney:mjserver:add")
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody MjServerBo bo) {
        return toAjax(mjServerService.insertByBo(bo));
    }

    /**
     * 修改MJ服务器信息配置
     */
    @SaCheckPermission("ruoyi-midjourney:mjserver:edit")
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody MjServerBo bo) {
        return toAjax(mjServerService.updateByBo(bo));
    }

    /**
     * 删除MJ服务器信息配置
     *
     * @param ids 主键串
     */
    @SaCheckPermission("ruoyi-midjourney:mjserver:remove")
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(mjServerService.deleteWithValidByIds(List.of(ids), true));
    }
}
